package com.vvlive.caibao.smartcity.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.amap.api.maps2d.model.Text;
import com.vvlive.caibao.smartcity.base.SuperAdapter;
import com.vvlive.caibao.smartcity.bean.FileDetails;

import java.util.List;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by zhj on 2015/12/14.
 * 文件类型Adapter
 */
public class FilesTypeAdapter extends SuperAdapter<FileDetails> {

    /**
     * 文件类型总数目
     */
    private static final int FILE_TYPES_COUNT = 7;

    private static int mIcons[] = {
            R.mipmap.file_audio,
            R.mipmap.file_picture,
            R.mipmap.file_video,
            R.mipmap.file_txt,
            R.mipmap.file_pdf,
            R.mipmap.file_word,
            R.mipmap.file_other
    };

    private static String[] mNames = {
            "音频", "图片", "视频", "TXT", "PDF", "WORD", "其他"
    };

    public FilesTypeAdapter(Context context, List<FileDetails> dataList) {
        super(context, R.layout.item_file_type, dataList);
    }

    @Override
    public void onBindData(ViewHolder viewHolder, FileDetails fileDetails, int position) {

        ImageView icon = viewHolder.get(R.id.file_type_icon);
        int type = fileDetails.getType();
        icon.setImageResource(mIcons[type]);

        TextView name = viewHolder.get(R.id.file_type_name);
        name.setText(fileDetails.getName());

        TextView count = viewHolder.get(R.id.file_type_count);
        count.setText(getCountText(type, fileDetails.getCount()));

    }

    private CharSequence getCountText(int type, int count) {
        if (type > -1 && count > -1) {
            return mNames[type] + "文件" + count + "个";
        }
        return "未知文件文件类型0个";
    }
}
